//202302104059鲁林
package dao;

import entity.School;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;

public class CommonDao {
    private static CommonDao commonDao = new CommonDao();
    private static Collection<School>schools;
    public static CommonDao getInstance() {
        return commonDao;
    }
    public int count(Connection conn, String tableName) throws SQLException {
        String sql = "select count(id) as cnt from " + tableName;
        PreparedStatement ps = conn.prepareStatement(sql);
        int counter = 0;
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            counter = rs.getInt("cnt");
        }
        JdbcHelper.close(rs, ps);
        return counter;
    }
}
